package com.dvt.faceScan;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.dvt.faceScan.httpUntil.Base64Util;
import com.dvt.faceScan.httpUntil.FileUtil;
import com.dvt.faceScan.httpUntil.HttpUtil;
import com.dvt.faceScan.httpUntil.PostThread;
import com.dvt.faceScan.widget.Config;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * 重要提示代码中所需工具类
 * FileUtil,Base64Util,HttpUtil,GsonUtils请从
 * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
 * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
 * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
 * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
 * 下载
 * 人脸注册
 * 4 ====》是员工id
 */

public class FaceRegister extends AppCompatActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    public static String add(HashMap<String, String> bmp,String ID){
       Iterator it = bmp.entrySet().iterator();
       Map.Entry entry = (Map.Entry) it.next();
       String bmpImg = (String)entry.getValue();  //强转
        int empid = Integer.parseInt(ID);
       // 请求url
       String url = "https://aip.baidubce.com/rest/2.0/face/v2/faceset/user/add";
       try{
           String imgParam = URLEncoder.encode(bmpImg, "UTF-8");
           String param ="uid=" + empid + "&user_info=" + "userInfo5" + "&group_id=" + "test_group_2" + "&images=" + imgParam;
           String accessToken =Config.token;
           //起一个子线程
           PostThread pt = new PostThread();
           pt.setAccessToken(accessToken);
           pt.setParam(param);
           pt.setUrl(url);
           pt.start();
           String result = null;
           try {
               while(true){
                   if(pt.getResult()==null){
                       Thread.currentThread().sleep(1000);
                   }else{
                       result = pt.getResult();
                       break;
                   }
               }
           }catch (Exception e){
               e.printStackTrace();
           }
           return result;
       }catch (Exception e){
           e.printStackTrace();
       }
       return null;
   }

}
